3. Events

4. Functions

2.5.8 Functions in Solidity

Functions are reusable piece of code where we often write the

business logic and can call it again and again anywhere in the

program.

A function can have four visibility types, which are as follows:

External

Public

Internal

Private

The visibility must be assigned to a function, otherwise it would throw

an error.

External: A contract can be called from another contract, provided

that the external contract already knows the calling contract by using

the external keyword as a part of the contract name.

Public: The keywords are used mostly in getters and setters as well

as functions that you wish to invoke on the contract directly. They

can also be used against the state variables.

Internal: The visibility is only from within the current contract or the

contracts derived from it.

Private: The visibility is only for the contract that they are defined in

and not in the derived contracts.

Hence, all the visibility in the order of decreasing permissiveness is

as follows:

Public > External > Internal > Private

2.5.8.1 Constructor

Constructor is a function with the same name as a contract. Every

contract can optionally have a maximum of one constructor in it.

However, unlike Java, the constructor can’t be overloaded. The